package org.dromara.common.core.utils;

import java.util.Arrays;
import java.util.Comparator;

/**
 * 描述:
 *
 * @Author: lbc
 * @Date: 2024-04-12 12:05
 * @email: 594599620@qq.com
 * @Description: keep coding
 */
public class ConverUtils {

    /**
     * cid
     *
     * @param sendId
     * @param receiveId
     * @param isGroup
     * @return
     */
    public static String generateCid(String sendId, String receiveId, boolean isGroup) {
        if (isGroup) {
            return "sg_" + sendId + "_" + receiveId;
        }
        return "si_" + sendId + "_" + receiveId;
    }

    /**
     * 生成会话id
     * 会话id 固定
     * 两个人会话 会话id只有一个
     * 群会话     会话id 为群号
     *
     * @param sendId    发送者ID
     * @param receiveId 接收者ID
     * @param isGroup   是否群聊
     * @return 会话id
     */
    public static String genFlexCid(String sendId, String receiveId, boolean isGroup) {
        if (isGroup) {
            return "sg_" + receiveId;
        }

        String[] ids = {sendId, receiveId};
        Arrays.sort(ids, Comparator.naturalOrder());
        return "si_" + ids[0] + "_" + ids[1];
    }

}
